//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Web;

namespace DNAide.Web
{
	public static partial class HttpAide
	{
		/// <summary>
		/// Perform a full Html encode on the specified string, which
		/// will go beyond the standard HttpUtility.HtmlEncode method.
		/// </summary>
		/// <param name="value">Value to encode</param>
		/// <returns>String</returns>
		public static String HtmlEncode(String value)
		{
			if (String.IsNullOrEmpty(value))
				return String.Empty;

			StringBuilder result = new StringBuilder();

			// Encode via standard method first
			string working = HttpUtility.HtmlEncode(value);

			for (int i = 0; i < working.Length; i++)
			{
				char character = working[i];
				int characterNum = (int)character;

				// Encode characters > 255
				if (characterNum > 255)
					result.AppendFormat("&#{0};", characterNum);
				else
					result.Append(character);
			}

			return result.ToString();
		}
	}
}
